<template>
	<view class="content">
		<view class="button-sp-area">
			<button class="button" type="primary" @click="toLogin()">实名登录</button>
			<button class="button" type="warn" @click="nmLogin()">匿名登录</button>
		</view>
		<view class="example-body">
			<view class="uni-box-head">
				<uni-title type="h1" align="center" title="直言献策使用介绍"></uni-title>
			</view>
			<view class="uni-box">
				<uni-title class="h3" type="h3" title="1 实名登录"></uni-title>
			</view>
			<view>
				<text class="uni-text">
					使用账号及初始密码首次登录，重新设置密码后再登录(保护账号安全性）。和领导对话时显示本人所在部门及真实姓名。
				</text>
			</view>
			<view class="uni-box">
				<uni-title class="h3" type="h3" title="2 匿名登录"></uni-title>
			</view>
			<view>
				<text class="uni-text">
					匿名和领导对话，不显示、不记录本人姓名及任何隐私信息，可放心使用。
				</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref ,getCurrentInstance} from "vue";
	import { nmlogin,boxlogin } from '@/api/msgbox'
	import { getToken, setToken, removeToken } from '@/utils/auth'
	import {piniastore} from "@/store/compinia";
	import { onLoad } from '@dcloudio/uni-app';
	
	let instance = getCurrentInstance(); // 获取组件实例
	
	function toLogin(){
		uni.navigateTo({
			url: '/pages/index/smlogin'
		});
	}
	//匿名登录
	function nmLogin(){
		let usertoken = uni.getStorageSync('usertoken');
		let loginForm = {usertoken};
		nmlogin(loginForm).then(response => {
			uni.setStorageSync('usertoken',response.usertoken);
			let loginForm = {
				username:response.usertoken,
				password:response.usertoken
			}
			//真实登录
			boxlogin(loginForm).then(res => {
				setToken(res.token);
				const ps = piniastore();
				ps.saveUser({userid:res.userid,usertype:res.usertype,needchgpass:res.needchgpass});
				uni.navigateTo({url: "/pages/index/sendmsg"});
			}).catch(() => {});
		}).catch(() => {
		});
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding:10px;
	}
	.button{
		margin:40px;
		font-size:30px;
	}
	.example-body {
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
		padding: 10px;
	}

	.uni-text {
		font-size: 14px;
		line-height: 22px;
		color: #333;
	}

</style>
